package com.etbsms.domain;

import java.io.File;
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Entity
@Table(name="Etbsms_Files")
public class Files implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -823470689563137713L;
	
	private int seq_no;
	private String original_name;
	private String stored_name;			
	private long size;
	private Date upload_time;
	private int update_user;
	private boolean enabled;
	private String path; 
	private String root_folder;
	private CommonsMultipartFile fileData;
	
	@Id
	@Column(nullable=false,name="seq_no")
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "identity")
	public int getSeq_no() {
		return seq_no;
	}
	public void setSeq_no(int seq_no) {
		this.seq_no = seq_no;
	}
	
	@Column(nullable=false,name="original_name")
	public String getOriginal_name() {
		return original_name;
	}
	public void setOriginal_name(String original_name) {
		this.original_name = original_name;
	}
	
	@Column(length=256,nullable=false)
	public String getStored_name() {
		return stored_name;
	}
	public void setStored_name(String stored_name) {
		this.stored_name = stored_name;
	}
	
	@Column(nullable=false,name="size")
	public long getSize() {
		return size;
	}
	public void setSize(long size) {
		this.size = size;
	}
	
	@Column(nullable=false,name="upload_time")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getUpload_time() {
		return upload_time;
	}
	public void setUpload_time(Date upload_time) {
		this.upload_time = upload_time;
	}
	
	@Column(nullable=false,name="enabled")
	public boolean isEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	/*
	@Column(nullable=false,name="path")
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	*/
	
	@Transient
	public String getPath() {
		String separator = File.separator;
		path = String.valueOf(this.getUpdate_user()) + separator + this.getStored_name();
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	
	@Transient
	public CommonsMultipartFile getFileData() {
		return fileData;
	}
	public void setFileData(CommonsMultipartFile fileData) {
		this.fileData = fileData;
	}
	
	@Transient
	public String getRoot_folder() {
		return root_folder;
	}
	public void setRoot_folder(String root_folder) {
		this.root_folder = root_folder;
	}
	
	@Column(nullable=false,name="update_user")
	public int getUpdate_user() {
		return update_user;
	}
	public void setUpdate_user(int update_user) {
		this.update_user = update_user;
	}
}
